home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / bgui12.lha / demos / Addbuttons.c < prev    next >
C/C++ Source or Header  |  1995-04-23  |  10KB  |  200 lines

  1. ;/*
  2. dcc addbuttons.c -mi -ms -mRR -proto -lbgui
  3. quit
  4. */
  5. /*
  6.  *      ADDBUTTONS.C
  7.  *
  8.  *      (C) Copyright 1994 Paul Weterings.
  9.  *          All Rights Reserved.
  10.  */
  11.  
  12. #include "democode.h"
  13.  
  14. /*
  15.  *      Object ID's. Please note that the ID's are shared
  16.  *      between the menus and the gadget objects.
  17.  */
  18. #define ID_ADD          21
  19. #define ID_QUIT         22
  20. #define ID_INS          23
  21. #define ID_REM          24
  22.  
  23. /*
  24.  *      Simple menu strip.
  25.  */
  26. struct NewMenu SimpleMenu[] = {
  27.         Title( "Project" ),
  28.                 Item( "Add",        "A", ID_ADD ),
  29.                 Item( "Insert",     "I", ID_INS ),
  30.                 Item( "Remove all", "R", ID_REM ),
  31.                 ItemBar,
  32.                 Item( "Quit",       "Q", ID_QUIT ),
  33.                 End
  34. };
  35.  
  36. /*
  37.  *      Simple button creation macros.
  38.  */
  39. #define AddButton\
  40.         ButtonObject,\
  41.                 LAB_Label,              "Added",\
  42.                 LAB_Style,              FSF_BOLD,\
  43.                 ButtonFrame,\
  44.         EndObject
  45.  
  46. #define InsButton\
  47.         ButtonObject,\
  48.                 LAB_Label,              "Inserted",\
  49.                 LAB_Style,              FSF_BOLD,\
  50.                 ButtonFrame,\
  51.         EndObject
  52.  
  53.  
  54. VOID StartDemo( void )
  55. {
  56.         struct Window           *window;
  57.         Object                  *WO_Window, *GO_Add, *GO_Quit, *GO_Ins, *GO_Rem, *addobj[20], *base;
  58.         ULONG                    signal = 0, rc, tmp = 0;
  59.         BOOL                     running = TRUE, ok = FALSE;
  60.         int                      x = 0, xx;
  61.  
  62.         /*
  63.          *      Create window object.
  64.          */
  65.         WO_Window = WindowObject,
  66.                 WINDOW_Title,           "Add/Insert Demo",
  67.                 WINDOW_MenuStrip,       SimpleMenu,
  68.                 WINDOW_LockHeight,      TRUE,
  69.                 WINDOW_AutoAspect,      TRUE,
  70.                 WINDOW_MasterGroup,
  71.                         base = HGroupObject,
  72.                                 StartMember, GO_Add  = XenKeyButton( "_Add",        ID_ADD  ), EndMember,
  73.                                 StartMember, GO_Ins  = XenKeyButton( "_Insert",     ID_INS  ), EndMember,
  74.                                 StartMember, GO_Rem  = XenKeyButton( "_Remove all", ID_REM  ), EndMember,
  75.                                 StartMember, GO_Quit = XenKeyButton( "_Quit",       ID_QUIT ), EndMember,
  76.                         EndObject,
  77.         EndObject;
  78.  
  79.         /*
  80.          *      OK?
  81.          */
  82.         if ( WO_Window ) {
  83.                 /*
  84.                  *      Add gadget hotkeys.
  85.                  */
  86.                 tmp += GadgetKey( WO_Window, GO_Add,  "a" );
  87.                 tmp += GadgetKey( WO_Window, GO_Quit, "q" );
  88.                 tmp += GadgetKey( WO_Window, GO_Ins,  "i" );
  89.                 tmp += GadgetKey( WO_Window, GO_Rem,  "r" );
  90.                 /*
  91.                  *      Keys OK?
  92.                  */
  93.                 if ( tmp == 4 ) {
  94.                         /*
  95.                          *      Open window.
  96.                          */
  97.                         if ( window = WindowOpen( WO_Window )) {
  98.                                 /*
  99.                                  *      Get signal mask.
  100.                                  */
  101.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  102.                                 do {
  103.                                         /*
  104.                                          *      Poll messages.
  105.                                          */
  106.                                         Wait( signal );
  107.                                         while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  108.                                                 switch ( rc ) {
  109.  
  110.                                                         case  WMHI_CLOSEWINDOW:
  111.                                                         case  ID_QUIT:
  112.                                                                 /*
  113.                                                                  *      Bye now.
  114.                                                                  */
  115.                                                                 running = FALSE;
  116.                                                                 break;
  117.  
  118.                                                         case  ID_ADD:
  119.                                                                 if ( x == 19 ) {
  120.                                                                         Tell( "Max Nr. of gadgets\n" );
  121.                                                                         break;
  122.                                                                 }
  123.                                                                 x++;
  124.                                                                 WindowClose( WO_Window );
  125.  
  126.                                                                 addobj[x]  = AddButton;
  127.  
  128.                                                                 ok = DoMethod( base, GRM_ADDMEMBER, addobj[ x ],
  129.                                                                                 LGO_FixMinHeight, FALSE,
  130.                                                                                 LGO_Weight,       DEFAULT_WEIGHT,
  131.                                                                                 TAG_END );
  132.  
  133.                                                                 window = WindowOpen( WO_Window );
  134.  
  135.                                                                 if ( ok && ! window ) {
  136.                                                                         DoMethod( base, GRM_REMMEMBER, addobj[ x ] );
  137.                                                                         x--;
  138.                                                                         window = WindowOpen( WO_Window );
  139.                                                                         Tell( "Last object did not fit!\n" );
  140.                                                                 }
  141.  
  142.                                                                 if ( ! window )
  143.                                                                         goto error;
  144.                                                                 break;
  145.  
  146.                                                         case  ID_REM:
  147.                                                                 if ( x > 0 ) {
  148.                                                                         WindowClose( WO_Window );
  149.  
  150.                                                                         for ( xx = 1; xx <= x; xx++ )
  151.                                                                                 DoMethod( base, GRM_REMMEMBER, addobj[ xx ] );
  152.  
  153.                                                                         window = WindowOpen( WO_Window );
  154.                                                                         x = 0;
  155.                                                                 } else
  156.                                                                         Tell("Were out of gadgets!\n");
  157.  
  158.                                                                 break;
  159.  
  160.                                                         case  ID_INS:
  161.                                                                 if ( x == 19 ) {
  162.                                                                         Tell( "Max Nr. of gadgets\n" );
  163.                                                                         break;
  164.                                                                 }
  165.                                                                 x++;
  166.                                                                 WindowClose( WO_Window );
  167.  
  168.                                                                 addobj[x]  = InsButton;
  169.  
  170.                                                                 ok = DoMethod( base, GRM_INSERTMEMBER, addobj[ x ], GO_Rem,
  171.                                                                                 LGO_FixMinHeight, FALSE,
  172.                                                                                 LGO_Weight,       DEFAULT_WEIGHT,
  173.                                                                                 TAG_END );
  174.  
  175.                                                                 window = WindowOpen( WO_Window );
  176.  
  177.                                                                 if ( ok && ! window ) {
  178.                                                                         DoMethod( base, GRM_REMMEMBER, addobj[ x ] );
  179.                                                                         x--;
  180.                                                                         window = WindowOpen( WO_Window );
  181.                                                                         Tell( "Last object did not fit!\n" );
  182.                                                                 }
  183.  
  184.                                                                 if ( ! window )
  185.                                                                         goto error;
  186.                                                                 break;
  187.  
  188.                                                 }
  189.                                         }
  190.                                 } while ( running );
  191.                         } else
  192.                                 Tell( "Could not open the window\n" );
  193.                 } else
  194.                         Tell( "Could not assign gadget keys\n" );
  195.                 error:
  196.                 DisposeObject( WO_Window );
  197.         } else
  198.                 Tell( "Could not create the window object\n" );
  199. }
  200.